#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Time          : 2023/1/3 16:12
# File          : judge_weekday.py
# @Author       : MingTai
# @Department   : platform_qa

import requests
from bs4 import BeautifulSoup as BS


# 获取指定月份节假日
def get_holidays(year, month):
    result = {}

    url = f"https://www.rili.com.cn/wannianli/{year}/{month}/"
    content = requests.get(url)
    bs = BS(content.text)

    holidays = ['春节', '元旦', '除夕', '元宵节', '清明节', '劳动节', '端午节', '中秋节', '国庆节']

    tds = bs.find("table").find("table").find_all("td")

    for td in tds:
        if 'noby' in td['class']:
            continue

        day = td.select(".riwai>.ri")[0].text
        name1 = td.select(".riwai>.jie")
        name2 = td.select(".riwai>.r2")
        if len(name1) > 0:
            name = name1[0].text
        if len(name2) > 0:
            name = name2[0].text

        if name in holidays:
            result[f"{year}-{month}-{day}"] = name

    return result


def test_holiday(i):
    print('开始')
    if i == 1:
        return
    print('结束')
    return 'test success'


def get_holidays_2023():
    holiday_list = ['2023-01-23', '2023-01-24', '2023-01-25', '2023-01-26', '2023-01-27', '2023-04-05', '2023-05-01',
                    '2023-05-02', '2023-06-22', '2023-06-23', '2023-09-29', '2023-10-02', '2023-10-03', '2023-10-04',
                    '2023-10-05', '2023-10-06', '2024-01-01']
    return holiday_list


def test_return():
    time = '2023-10-09'
    if time in get_holidays_2023():
        print('是节假日')
        return
    print('后续执行')


if __name__ == "__main__":
    # holidays = {}
    #
    # for year in range(1990, 1995):
    #     for month in range(1, 13):
    #         holidays.update(get_holidays(year, month))

    # print(test_holiday(i=1))
    test_return()
